package com.kgcx.organization.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.kgcx.common.bean.RequestData;
import com.kgcx.common.constant.Cons;
import com.kgcx.dbutils.domain.BaseDomain;
import com.kgcx.dbutils.utils.PageUtils;
import com.kgcx.organization.domain.StationParking;
import com.kgcx.organization.mapper.StationParkingMapper;

@Service
public class StationParkingService {
    @Autowired
    private StationParkingMapper stationParkingMapper;

    public StationParking getStationParking(Long kid) {
        return stationParkingMapper.selectByPrimaryKey(kid);
    }

    public List<StationParking> getStationParkingList(RequestData rd) {
        PageUtils.page(rd);
        PageHelper.orderBy(rd.getOrderBy());
        return stationParkingMapper.getStationParking(BaseDomain.buildSelectDomain(rd, new StationParking()));
    }

    @Transactional(rollbackFor = Exception.class)
    public void addStationParking(StationParking stationParking) {
        stationParkingMapper.insertSelective(stationParking);
    }

    @Transactional(rollbackFor = Exception.class)
    public void updateStationParking(StationParking stationParking) {
        stationParkingMapper.updateByPrimaryKeySelective(stationParking);
    }

    @Transactional(rollbackFor = Exception.class)
    public void removeStationParking(Long kid) {
        StationParking stationParking = new StationParking();
        stationParking.setKid(kid);
        stationParking.setStatus(Cons.COMMON_STATUS_DELETE);
        stationParkingMapper.updateByPrimaryKeySelective(stationParking);
    }
}
